package com.etooling.pdm.repository;

import com.etooling.framework.repository.BaseRepository;
import com.etooling.pdm.entity.Goods;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

@Repository
public interface GoodsRepository extends BaseRepository<Goods> {

    @Query(nativeQuery = true, value = "select count(1) from pdm.t_goods g where g.material_code=?1 and company_id=?2 and status!=?3")
    Integer countMaterialCode(String materialCode, String companyId, String neStatus);


    @Query(nativeQuery = true, value = "select count(1) from pdm.t_goods g " +
            "                           left join pdm.t_goods_type gt on g.goods_type_id = gt.id " +
            "                           where g.material_code=?1 and g.company_id=?2 and g.status!=?3 and gt.is_product=?4 ")
    Integer countMaterialCode(String materialCode, String companyId, String neStatus, Boolean isProduct);


    @Query(nativeQuery = true, value = "select * from pdm.t_goods where material_code = ?1 and company_id =?2 and status = '启用' ")
    Goods getGoodsByMaterialCode(String materialCode, String companyId);


}
